package com.liaogui.锁.sync;

import java.util.concurrent.TimeUnit;

/**
 * 静态代码块
 * @author liaogui
 * @date 2025/3/31 22:48
 */
public class Test03 {
    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            Data2 data2 = new Data2();
            new Thread(() ->{
                data2.fun1();
            }).start();
        }
    }
}
class Data2 {
    public void fun1() {
        synchronized (this) {
            System.out.println("start...");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("end...");
        }

    }

    public void fun2() {
        synchronized (Data2.class) {
            System.out.println("start...");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("end...");
        }

    }
}
